/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package librairie;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 *
 * @author Khémon Beh & Florian Minin
 */
public class Transport {

    private ObjectOutputStream out;
    private ObjectInputStream in;
    private Socket s;

    public Transport(String host, int port) throws IOException {
        s = new Socket(host, port);
        out = new ObjectOutputStream(s.getOutputStream());
        in = new ObjectInputStream(s.getInputStream());
    }
    
    public Transport(Socket _s) throws IOException {
        s = _s;
        in = new ObjectInputStream(s.getInputStream());
        out = new ObjectOutputStream(s.getOutputStream());
    }

    public void envoyer(Object m) throws IOException {
        out.writeObject(m);
    }
    
    public Object recevoir() throws IOException, ClassNotFoundException{
        return in.readObject();
    }
    
    public void fermer() throws IOException {
        out.close();
        in.close();
        s.close();
    }
}
